home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1830 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  29 lines

  1. Newsgroups: comp.lang.c
  2. Path: thinkage.on.ca!atbowler
  3. From: atbowler@thinkage.on.ca (Alan Bowler)
  4. Subject: Re: Trouble with file return code.
  5. Message-ID: <DLAv0C.GqF@thinkage.on.ca>
  6. Sender: news@thinkage.on.ca
  7. Organization: Thinkage Ltd.
  8. References: <tcpnntpd.16.1.10.20.22.42.2781597121.333610@the-fix.sos.on.ca> <4d3h96$9fl@news.iag.net>
  9. Date: Wed, 17 Jan 1996 00:36:12 GMT
  10.  
  11. In article <4d3h96$9fl@news.iag.net> jatmon@iag.net (John R Buchan) writes:
  12. >      
  13. >   /* Of course, you'll want to do better i/o testing, but basically */
  14. >   while( fread(buf, sizeof(buf), 1, ptr) == 1)
  15.  
  16. I know you covered yourself with a disclaimer, but this one is very
  17. dicy.  If fread get an EOF part way though the "sizeof buf" bytes
  18. it may return 0 or 1.  (does the library round up or down?).
  19. I suggest
  20.  
  21.    while(sizeof buf == (count = fread(buf, 1, sizeof(buf), ptr))) {
  22.           /* play with the record */
  23.    }
  24.    if (0 != count) 
  25.         error("last record was incomplete. and had only %d bytes", count);
  26.  
  27. I watch this one carefully because we bit a set of users once when
  28. we changed the round up/down choice in our library.
  29.